{% extends 'base.html' %}
{% from 'bootstrap/pagination.html' import render_pagination %}

{% block title %}{{ _('Manage Comments') }}{% endblock %}

{% block content %}
    <div class="page-header">
        <h1>{{ _('Comments') }}
            <small class="text-muted">{{ pagination.total }}</small>
        </h1>
        <ul class="nav nav-pills">
            <li class="nav-item">
                <a href="#" class="nav-link disabled">{{ _('Filter') }}</a>
            </li>
            <li class="nav-item">
                <a href="{{ url_for('admin.manage_comment', filter='all') }}" class="nav-link {% if request.args.get('filter', 'all') == 'all' %}active{% endif %}">
                    {{ _('ALL') }}
                </a>
            </li>
            <li class="nav-item">
                <a href="{{ url_for('admin.manage_comment', filter='unread') }}" class="nav-link {% if request.args.get('filter') == 'unread' %}active{% endif %}">
                    {{ _('Unread') }}
                    {% if unread_comments %}
                        <span class="badge badge-success">{{ unread_comments }}</span>
                    {% endif %}
                </a>
            </li>
            <li class="nav-item">
                <a href="{{ url_for('admin.manage_comment', filter='admin') }}" class="nav-link {% if request.args.get('filter') == 'admin' %}active{% endif %}">
                    {{ _('Admin') }}
                </a>
            </li>
        </ul>
    </div>
    {% if comments %}
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>{{ _('No.') }}</th>
                    <th>{{ _('Author') }}</th>
                    <th>{{ _('Body') }}</th>
                    <th>{{ _('Date') }}</th>
                    <th>{{ _('Actions') }}</th>
                </tr>
            </thead>
            {% for comment in comments %}
                <tr {% if not comment.reviewed %}class="table-warning"{% endif %}>
                    <td>{{ loop.index + ((pagination.page - 1) * config['BLUELOG_COMMENT_PER_PAGE']) }}</td>
                    <td>
                        {% if comment.from_admin %}{{ admin.name }}{% else %}{{ comment.author }}{% endif %}
                        {% if comment.site %}
                            <a href="{{ comment.site }}" target="_blank">{{ comment.site }}</a><br>
                        {% endif %}
                        <a href="mailto:{{ comment.email }}">{{ comment.email }}</a>
                        {% if comment.from_admin %}
                            <span class="badge badge-primary">{{ _('Author') }}</span>
                        {% endif %}
                    </td>
                    <td>{{ comment.body }}</td>
                    <td>{{ moment(comment.timestamp).format('LL') }}</td>
                    <td>
                        {% if not comment.reviewed %}
                            <form class="inline" method="post" action="{{ url_for('.approve_comment', comment_id=comment.id, next=request.full_path) }}">
                                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
                                <button type="submit" class="btn btn-success btn-sm">{{ _('Approve') }}</button>
                            </form>
                        {% endif %}
                        <a class="btn btn-info btn-sm" href="{{ url_for('blog.show_post', post_id=comment.post.id) }}">{{ _('Post') }}</a>
                        <form class="inline" method="post" action="{{ url_for('.delete_comment', comment_id=comment.id, next=request.full_path) }}">
                            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
                            <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('{{ _('Are you sure?') }}');">{{ _('Delete') }}</button>
                        </form>
                    </td>
                </tr>
            {% endfor %}
        </table>
        <div class="page-footer">{{ render_pagination(pagination) }}</div>
    {% else %}
        <div class="tip"><h5>No comments.</h5></div>
    {% endif %}
{% endblock %}
